maintenance_list 增加筛选

FFIB 3 年之前
父節點
當前提交
e5da057cbc
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      api/maintenance_views.py

+ 17 - 0
api/maintenance_views.py

@@ -3,8 +3,10 @@
3 3
 from __future__ import division
4 4
 
5 5
 import json
6
+from datetime import datetime
6 7
 
7 8
 from django.conf import settings
9
+from django.db.models.query_utils import Q
8 10
 from django_logit import logit
9 11
 from django_response import response
10 12
 from paginator import pagination
@@ -181,10 +183,25 @@ def maintenance_list(request):
181 183
     user_id = request.POST.get('user_id', '')
182 184
     page = request.POST.get('page', 1)
183 185
     num = request.POST.get('num', 20)
186
+    query = request.POST.get('query', '')
187
+    maintenance_status = request.POST.get('maintenance_status', '')
188
+    start_time = request.POST.get('start_time', '')
189
+    end_time = request.POST.get('end_time', '')
184 190
 
185 191
     maintenances = MaintenaceInfo.objects.filter(status=True)
186 192
     if not is_admin(brand_id, admin_id):
187 193
         maintenances = maintenances.filter(user_id=user_id)
194
+    
195
+    if start_time and end_time:
196
+        start_time = datetime.strptime(start_time, '%Y%m%d')
197
+        end_time = datetime.strptime(end_time + ' 23:59:59', '%Y%m%d %H:%M:%S')
198
+        maintenances = maintenances.filter(created_at__range=(start_time, end_time))
199
+
200
+    if query:
201
+        maintenances = maintenances.filter(Q(phone=query) | Q(name__icontains=query) | Q(sn=query))
202
+    
203
+    if maintenance_status:
204
+        maintenances = maintenances.filter(maintenance_status=maintenance_status)
188 205
 
189 206
     count = maintenances.count()
190 207
     maintenances = [maintenance.data for maintenance in maintenances]